package PagePackage;
import static org.testng.AssertJUnit.assertEquals;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;


public class teamsPage  extends internalPageClass{
	@FindBy (className="btn-add-new")
	public WebElement addNewTeamButton;
	
	
	@FindBy (name="name")
	public WebElement teamName;
	
	@FindBy (className="btn-search")
	public WebElement searchButton;
	
public newTeamPage scrollAndClickTeam( int x, int y, String teamName) {
		 /*boolean present;
		    try {
		WebElement newTeamClick=driver.findElement(By.xpath(teamName));
		 
	  String code = "window.scroll(" + (newTeamClick.getLocation().x + x) + ","
	                              + (newTeamClick.getLocation().y + y) + ");";

	  ((JavascriptExecutor)driver).executeScript(code, newTeamClick, x, y); 
	  
	      present = true;
	   } catch (NoSuchElementException e) {
	      present = false;
	   }
		    assertEquals(false, present);
		 return MyPageFactory.getPage(driver, newTeamPage.class);*/
	
	WebElement newTeamClick=driver.findElement(By.xpath(teamName));
	 
    String code = "window.scroll(" + (newTeamClick.getLocation().x + x) + ","
                                 + (newTeamClick.getLocation().y + y) + ");";
 
    ((JavascriptExecutor)driver).executeScript(code, newTeamClick, x, y);
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", newTeamClick);
   /* WebElement edit2 = newTeamClick.findElement(By.xpath("../../td[2]/div/a"));
	 ((JavascriptExecutor) driver).executeScript("arguments[0].click();", edit2);*/
	 return MyPageFactory.getPage(driver, newTeamPage .class);
		 
	
	}
	
public newTeamPage clickAddNewTeamButton() {
	addNewTeamButton.click();
	return MyPageFactory.getPage(driver, newTeamPage.class);
}


public teamsPage scrollAndClickTeam2(int x, int y, String teamName) {
	 boolean present;
	    try {
	WebElement newTeamClick=driver.findElement(By.xpath(teamName));
	 
  String code = "window.scroll(" + (newTeamClick.getLocation().x + x) + ","
                              + (newTeamClick.getLocation().y + y) + ");";

  ((JavascriptExecutor)driver).executeScript(code, newTeamClick, x, y); 
  
      present = true;
   } catch (NoSuchElementException e) {
      present = false;
   }
	    assertEquals(false, present);
	 return MyPageFactory.getPage(driver, teamsPage.class);
	 
}


public teamsPage findTeam(String team){
	teamName.click();
	teamName.clear();
	teamName.sendKeys(team);
	searchButton.click();
	 return MyPageFactory.getPage(driver, teamsPage.class);
}

public boolean isOnThisPage(){
	return addNewTeamButton.isDisplayed();
}

@Override
void tryToOpen() {
MyPageFactory.getPage(driver, loginPageClass.class).loginAs("victoria@krossover.com", "webmaster");
MyPageFactory.getPage(driver, userRolePageClass.class).clickTeamTab();
	
}
}